Skip to content

#241 - Fix CsvWriterTask: non-array input without headers, execution after finalize() - #247

Merged
njoubert-cleverage merged 1 commit into
mainfrom
241
Oct 9, 2026
Merged

njoubert-cleverage merged 1 commit into
mainfrom
241

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #241.

  1. Non-array input with headers: null: CsvWriterTask::getHeaders() called array_keys($state->getInput()) when opening the file, before the input was validated, so a non-array input threw a raw TypeError. The input is now checked first and the documented \UnexpectedValueException('Input value is not an array') is thrown (same exception as with static headers), before the file is created.
  2. Execution after finalize(): AbstractCsvResourceTask::finalize() closed the file without resetting $this->csv, so a second execution of the same instance threw CSV file '...' was closed earlier. It is now reset to null. This does not happen through the ProcessManager (task services are not shared), but makes the CSV tasks consistent with CsvSplitterTask, which already did it in its own finalize() (now identical to the parent one, left untouched to stay in scope). CsvReaderTask / InputCsvReaderTask inherit it: calling finalize() before the end of the file no longer prevents a following read.

Documentation: docs/reference/tasks/csv_writer_task.md (non-array input). Tests: CsvWriterTaskTest::testThrowsWhenInputIsNotAnArrayWithoutStaticHeaders and testCanWriteAgainAfterFinalize, both failing on main for the reported reasons.

PHPUnit (803 tests), PHPStan, PHP-CS-Fixer and Rector pass, and the changed files are valid PHP 8.2.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: both cases currently throw (a TypeError and a RuntimeException).

🤖 Generated with Claude Code

…nted `\UnexpectedValueException` instead of a `TypeError` when `headers` is `null`, and the CSV tasks release their file on `finalize()` so that the task can be executed again. Update documentation, add tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit 843c859 into main Oct 9, 2026
17 checks passed
@njoubert-cleverage
njoubert-cleverage deleted the 241 branch October 9, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CsvWriterTask: a non-array input throws a TypeError when headers is null, and the task cannot run again after finalize()

1 participant